//
//  AppDelegate.m
//  app
//
//  Created by mac on 2021/6/29.
//

#import "AppDelegate.h"
#import "ViewController.h"

#define Screen_Width        [UIScreen mainScreen].bounds.size.width
#define Screen_Height       [UIScreen mainScreen].bounds.size.height
#define Is_Iphone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define Is_IPhoneX (Screen_Width >=375.0f && Screen_Height >=812.0f && Is_Iphone)

#define StatusBar_Height    (Is_IPhoneX ? (44.0):(20.0))
#import <UserNotifications/UserNotifications.h>

@interface AppDelegate () <UNUserNotificationCenterDelegate>

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    //注册本地推送
       UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
       center.delegate = self;
       [center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound)
                             completionHandler:^(BOOL granted, NSError * _Nullable error) {
                                 
                             }];
       
       //获取当前的通知设置
       [center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
           
       }];
    
    if (@available(iOS 13.0, *)) {
      
        } else {
          
            self.window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0,Screen_Width , Screen_Height)];
            
            ViewController * vc = [[ViewController alloc] init];
            
            self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:vc];
            
            [self.window makeKeyAndVisible];
            
        }


    
    return YES;
}


- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
    completionHandler(UNNotificationPresentationOptionAlert);
}
//- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
//
//    NSString *categoryIdentifier = response.notification.request.content.categoryIdentifier;
//
//    // UNNotificationCategory
//    if ([categoryIdentifier isEqualToString:@"categoryIdentifier"]) {
//        // UNNotificationAction、UNTextInputNotificationAction
//        if ([response.actionIdentifier isEqualToString:@"cancelAction"]) {
//
//        }
//    }
//
//    NSDictionary * userInfo = response.notification.request.content.userInfo;
//    UNNotificationRequest *request = response.notification.request; // 收到推送的请求
//    UNNotificationContent *content = request.content; // 收到推送的消息内容
//
//    if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
//        NSLog(@"iOS10 收到远程通知");
//    } else {
//        // 本地通知
//        NSLog(@"iOS10 收到本地通知");
//    }
//
//    completionHandler();
//}

#pragma mark - UISceneSession lifecycle


- (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options {
    // Called when a new scene session is being created.
    // Use this method to select a configuration to create the new scene with.
    return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role];
}


- (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)sceneSessions {
    // Called when the user discards a scene session.
    // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
    // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}


@end
